package com.zzsy.carosshopprojects.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.SpannableString;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.king.base.adapter.ViewHolderAdapter;
import com.king.base.adapter.holder.ViewHolder;
import com.yatoooon.screenadaptation.ScreenAdapterTools;
import com.zzsy.carosshopprojects.R;
import com.zzsy.carosshopprojects.base.ConfigureFile;
import com.zzsy.carosshopprojects.bean.GetOilsListBean;
import com.zzsy.carosshopprojects.util.StringUtils;
import com.zzsy.carosshopprojects.util.ViewBgUtil;

import java.util.List;

public class ChoseOilAdapter extends ViewHolderAdapter<GetOilsListBean> {
    private int pos = -1;
    private boolean isShow;//true 只显示6个

    public ChoseOilAdapter(Context context, List<GetOilsListBean> listData, int layoutId, boolean isShow) {
        super(context, listData, layoutId);
        this.isShow = isShow;
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, GetOilsListBean bean, int position, ViewGroup parent) {
        View view = layoutInflater.inflate(R.layout.adapter_choseoil, null, false);
        ScreenAdapterTools.getInstance().loadView(view);
        return view;
    }


    @Override
    public void bindViewDatas(ViewHolder helper, GetOilsListBean bean, int positions) {
//        if (isShow && positions > 5) {
//            return;
//        }
        String number = bean.getPnumber();
        String oilType = bean.getProductId();
        TextView tv_content = helper.getView(R.id.tv_content);
        if ("1".equals(oilType)) {
            String content = number + "  柴";
            SpannableString spannableString = StringUtils.setFontSizeSp(getContext(), content, 0, number.length(), 20);
            tv_content.setText(spannableString);
        } else if ("2".equals(oilType)) {
            String content = number + "  汽";
            SpannableString spannableString = StringUtils.setFontSizeSp(getContext(), content, 0, number.length(), 20);
            tv_content.setText(spannableString);
        } else {
            String content = number + "";
            SpannableString spannableString = StringUtils.setFontSizeSp(getContext(), content, 0, number.length(), 20);
            tv_content.setText(spannableString);
        }
        if (pos == positions) {
            tv_content.setBackground(ViewBgUtil.setBg(10, Color.parseColor(ConfigureFile.ColorSystem)));
            tv_content.setTextColor(Color.parseColor(ConfigureFile.ColorWhite));
        } else {
            tv_content.setBackground(ViewBgUtil.setWidthBg(10, 2, Color.parseColor("#efefef"), Color.parseColor("#efefef")));
            tv_content.setTextColor(Color.parseColor("#333333"));
        }

    }

    public void   setPostion(int p) {
        pos = p;
        notifyDataSetChanged();
    }

}
